package com.my.es.test.doc;

import org.apache.http.HttpHost;
import org.elasticsearch.action.bulk.BulkRequest;
import org.elasticsearch.action.bulk.BulkResponse;
import org.elasticsearch.action.delete.DeleteRequest;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;

import java.io.IOException;

/**
 * @author zhupanlin
 * @version 1.0
 * @description: TODO
 * @date 2024/5/9 16:39
 */
public class ESTest_Doc_Delete_Batch {

    public static void main(String[] args) throws IOException {
        RestHighLevelClient esClient = new RestHighLevelClient(RestClient.builder(new HttpHost("localhost", 9200, "http")));
        
        // 插入数据
        BulkRequest request = new BulkRequest();

        DeleteRequest userRequest1 = new DeleteRequest().index("user").id("1001");

        DeleteRequest userRequest2 = new DeleteRequest().index("user").id("1002");

        DeleteRequest userRequest3 = new DeleteRequest().index("user").id("1003");

        request.add(userRequest1);
        request.add(userRequest2);
        request.add(userRequest3);


        BulkResponse response = esClient.bulk(request, RequestOptions.DEFAULT);
        System.out.println("response.getIngestTookInMillis() = " + response.getIngestTookInMillis());
        System.out.println("response.getItems() = " + response.getItems());


        esClient.close();
    }
    
}
